<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        html {
            font-size: 20px !important;
        }

        .aui-title {
            color: #303030 !important;
            font-size: 0.8rem !important;
        }

        .icon_img {
            width: 0.8rem;
            height: 0.8rem;
            margin-right: 0.7rem;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav aui-bar-light hd" id="app">
        <a id="back" class="aui-pull-left aui-btn">
            <img src="../image/icon_back.png" style="width: 0.45rem;height: 0.8rem;margin-left: 0.7rem;" alt="">
        </a>
        <div class="aui-title">
            邀请有礼
        </div>

        <a class="aui-pull-right aui-btn">
            <img class="icon_img" src="../image/icon_share.png" onclick="share()" />
        </a>
    </header>



</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready()
        hb_openframeby_auto('invite_colleagues_frm', api.pageParam)
        api.addEventListener({
            name: 'yaoqing'
        }, function (ret, err) {
            share();
        });
        // alert(JSON.stringify($api.getStorage("emp")))
    };

    var app = new Vue({
        el: "#app",
        data: {
            link: ""
        }
    })

    //点击了分享按钮
    function share() {
        // if (!checkLogin()) {
        //     return
        // }
        var dialogBox = api.require('dialogBox');
        dialogBox.actionMenu({
            rect: {
                h: 170
            },
            texts: {
                cancel: '取消'
            },
            items: [{
                text: '朋友圈',
                icon: 'widget://image/pengyou@2x.png'
            }, {
                text: '微信',
                icon: 'widget://image/wx@2x.png'
            }, {
                text: '二维码',
                icon: 'widget://image/ucenter/qrcode.png'
            }],
            styles: {
                bg: '#FFF',
                column: 3,
                itemText: {
                    color: '#000',
                    size: 12,
                    marginT: 8
                },
                itemIcon: {
                    size: 50
                },
                cancel: {
                    bg: 'fs://icon.png',
                    color: '#999999',
                    h: 50,
                    size: 14,
                },
            },
            isCuttingLine: true,
            tapClose: true,
        }, function (ret) {
            if (ret.index == 0) {
                //alert('分享到朋友圈');
                WXhy_Pengyou('timeline'); //调用的微信朋友圈分享
            }
            if (ret.index == 1) {
                //alert('分享到微信好友');
                WXhy_Pengyou('session'); //调用的微信好友分享
            }
            if (ret.index == 2) {
                // 打开遮罩
                sendting("open")
            }
            dialogBox.close({
                dialogName: 'actionMenu'
            });
        });

    }
    //调用的微信好友或微信朋友圈分享
    function WXhy_Pengyou(typename) {
        //alert(555)
        var wx = api.require('wxPlus');
        wx.isInstalled(function (ret, err) {
            if (!ret.installed) {
                api.alert({
                    msg: "分享失败"
                });
            } else {
                get_ajax("doctor/invite/link", {
                    cellphone: $api.getStorage("emp").phone
                }, function (res, err) {
                    // console.log(JSON.stringify(res.data))
                    if (res.code == 2000) {
                        app.link = res.data
                        wx.shareWebpage({
                            apiKey: '',
                            scene: typename,
                            title: "祥愿堂医生邀请同行",
                            description: $api.getStorage("emp").name + "医生邀请您加入祥愿堂，携手共进",
                            thumb: "../image/logo.png",
                            contentUrl: res.data
                        }, function (ret, err) {
                            if (ret.status) {
                                toast('分享成功');
                            } else {
                                toast('分享被取消');
                            }
                        });
                    } else {
                        toast("开小差了，请稍后再试")
                    }
                })


            }
        });
    }
</script>

</html>